|
|
|
|
|
|
|
Upon allocating environment and connection handles, you can open one or more connections to remote database servers by using a different connection handle (hDbc) for each database connection. Sophisticated enterprise applications you write in Visual Basic might require that you open more than one connection to support simultaneous action queries. For less sophisticated applications, only one connection is sufficient. You have to weigh having more than one hDbc handle allocated versus simply allocating more than one hStmt handleone for each SQL statement in which the fulfillment of a query doesn't depend on the fulfillment of another. |
|
|
|
|
|
|
|
|
Tip Use the ODBC's SQLGetInfo function to verify whether your database driver supports multiple active statements on a single connection before allocating more than one hStmt handle. Otherwise, you might receive an error. |
|
|
|
|
|
|
|
|
|
Using the SQLConnect function in the ODBC API, you pass it a data source name, user ID, and password as arguments. Internally, SQLConnect changes the state of the newly acquired hDbc to Connected. The returned values you need to check for include SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, and SQL_ERROR. Other connection functions you can use include SQLDriverConnect and SQLBrowseConnect. |
|
|
|
|
|
|
|
|
SQLDriverConnect accepts DSN connection stringsfor example, |
|
|
|
|
|
|
|
|
DSN=MyDSN;UID=MyID;PWD=MyPWD |
|
|
|
|
|
|
|
|
To set the ODBC connection time-out, use the SQLSetConnectionOption function. Your application will receive an error if the syntax of the string is missing a parameter or has a misspelling. Check for the SQL_ERROR return value if the user cancels the connection request or if the driver manager is unable to connect to the data source. |
|
|
|
|
|
|
|
|
Using SQLBrowseConnect, you can obtain a list of available drivers, data sources, and other parameters. Your application chooses from available data items. Ideally, you can list these data items in a list box to let a user select one. |
|
|
|
|
|
|
|
|
To make your use of the ODBC API as painless as possible, create classes with the following names: |
|
|
|
|
|
|
|
|
ODBCEnvironment
ODBCConnection
ODBCResultset |
|
|
|
|
|